package main

import (
	"DmsRocketMQ/common"
	pro "DmsRocketMQ/producer/common"
	"DmsRocketMQ/producer/pub"
	"log"
	"time"
)

func main() {
	cfg, err := common.GetConfig()
	if err != nil {
		log.Printf("%+v", err)
		return
	}
	err = common.CreateTopic(cfg)
	if err != nil {
		log.Printf("%+v", err)
		return
	}
	p, err := pro.GetProducer(cfg)
	if err != nil {
		log.Printf("%+v", err)
		return
	}
	//发送同步消息
	err = pub.SendSyncMessage(p, "dmsgo", "send a sync msg!!")
	if err != nil {
		log.Printf("%+v", err)
		return
	}
	//发送异步消息
	err = pub.SendAsyncMessage(p, "dmsgo", "send a async msg!!")
	if err != nil {
		log.Printf("%+v", err)
		return
	}
	//发送延迟消息，延时一分钟
	err = pub.SendDelayMessage(p, "dmsgo", "send a delay msg on"+time.Now().Format("2006-01-02 15:04:05"), pub.OneMinute)
	if err != nil {
		log.Printf("%+v", err)
		return
	}
	//发送顺序消息
	err = pub.SendOrderlyMessage(p, "dmsgo", "send a orderly msg!!", "orderId")
	if err != nil {
		log.Printf("%+v", err)
		return
	}
}
